Skip to content

fix: make PrometheusMiddleware import-safe (fix #397) - #682

Open
vineoy wants to merge 2 commits into
taskiq-python:masterfrom
vineoy:fix/prometheus-duplicate-timeseries-397
Open

vineoy wants to merge 2 commits into
taskiq-python:masterfrom
vineoy:fix/prometheus-duplicate-timeseries-397

Conversation

@vineoy

@vineoy vineoy commented Sep 24, 2026

Copy link
Copy Markdown

Closes #397, relates #173.

Second PrometheusMiddleware() in the same process (e.g. broker module imported twice during --fs-discover) now reuses already-registered REGISTRY collectors instead of raising ValueError: Duplicated timeseries in CollectorRegistry.

Changes:

  • taskiq/middlewares/prometheus_middleware.py: get-or-create Counter/Histogram helpers + docstring fix
  • tests/middlewares/test_prometheus_middleware.py: regression for double instantiation and metric inc

Verified: new tests 2 passed, middlewares+cli 83 passed, full suite 370 passed (1 unrelated flaky opentelemetry test passes in isolation), ruff/black/mypy clean.

…eries

Creating multiple instances in the same process (e.g. when broker module is imported more than once during fs-discover) now reuses already registered collectors instead of raising ValueError: Duplicated timeseries in CollectorRegistry.

Closes taskiq-python#397, relates taskiq-python#173
@codecov

codecov Bot commented Sep 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.90909% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.24%. Comparing base (8a1b04d) to head (b5007c8).

Files with missing lines Patch % Lines
taskiq/middlewares/prometheus_middleware.py 90.90% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #682      +/-   ##
==========================================
+ Coverage   85.37%   86.24%   +0.87%     
==========================================
  Files          68       68              
  Lines        2660     2676      +16     
==========================================
+ Hits         2271     2308      +37     
+ Misses        389      368      -21     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

How to split the tasks into different modules without PrometheusMiddleware crashing the worker

1 participant